﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Win32;

namespace SteamSwitch
{
    public class SteamAPI
    {
        private static RegistryKey SteamReg = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Valve\Steam",true);
        /// <summary>
        /// 检测Steam是否安装
        /// </summary>
        /// <returns>返回是否</returns>
        public static bool GetSteamIsInstall()
        {
            if (SteamReg == null)
            {
                return false;
            }
            if (SteamReg.Name == @"HKEY_CURRENT_USER\SOFTWARE\Valve\Steam")
            {
                return true;
            }
            else
            {
                return false;
            }
            
        }

        /// <summary>
        /// 获取Steam安装路径
        /// </summary>
        /// <returns></returns>
        public static string GetSteamPath()
        {
            return SteamReg.GetValue("SteamPath").ToString();
        }

        /// <summary>
        /// 获取Steam.exe路径
        /// </summary>
        /// <returns></returns>
        public static string GetSteamExePath()
        {
            return SteamReg.GetValue("SteamExe").ToString();
        }

        /// <summary>
        /// 获取自动登陆的用户名
        /// </summary>
        /// <returns></returns>
        public static string GetAutoLoginUser()
        {
            return SteamReg.GetValue("AutoLoginUser").ToString();
        }

        /// <summary>
        /// 设置当前自动登陆用户名
        /// </summary>
        /// <param name="Username"></param>
        public static bool SetAutoLoginUser(string Username)
        {
            SteamReg.SetValue("AutoLoginUser", Username);
            if (GetAutoLoginUser() == Username)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
